package com.kintreda.ieco_server.module.api.web;

import com.kintreda.ieco_server.bean.goods.Items;
import com.kintreda.ieco_server.core.repository.IBaseRepository;
import com.kintreda.ieco_server.module.order.service.IRegenerantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Created by IntelliJ IDEA
 * @Project_Name ieco_server
 * @Package com.kintreda.ieco_server.module.api.web
 * @Author ZhongYao_H
 * @Date 2019/5/8:20:13
 * @Year 2019 Month 05 Day 08
 * @Date_zh 2019 年 五月 星期三
 */
@Controller
@RequestMapping("/api/regenerant")
public class ApiRegenerantController {

    @Autowired
    private IRegenerantService regenerantService;
    @Autowired
    private IBaseRepository<Items,String> itemsStringIBaseRepository;

    
    public List<Map<String,Object>> list(){
        return itemsStringIBaseRepository.findListBySql("select id,icon,name,type,typeA,typeB,money,remark from items where typeA = ? order by sorting asc",new Object[]{"1"});
    }


    /**
     * 查询分类物品
     *
     * @return
     */
    @RequestMapping(value = "/query",method = RequestMethod.POST)
    @ResponseBody
    public Object query(){
        List<Map<String, Object>> list = list();
        for (Map<String, Object> stringObjectMap : list) {
            List<Items> goods = regenerantService.query("from Items where type = ? ", new Object[]{stringObjectMap.get("id").toString()});
            stringObjectMap.put("goods",goods);
        }
        return   list;

    }
}
